﻿using OnHook.Domain.Enums;
using SqlSugar;

namespace OnHook.Domain.Entities
{
	/// <summary>
	/// 订单
	/// </summary>
	[SugarTable("t_order", TableDescription = "订单")]
	public class Order : AllBaseEntity
	{
		///<summary>
		/// 主键Id
		///</summary>
		[SugarColumn(IsPrimaryKey = true, ColumnName = "id", ColumnDescription = "主键Id")]
		public long Id { get; set; } = 0;
		///<summary>
		/// 用户的UserId
		///</summary>
		[SugarColumn(ColumnName = "user_id", ColumnDescription = "用户的UserId")]
		public long UserId { get; set; } = 0;
		///<summary>
		/// 商品Id
		///</summary>
		[SugarColumn(ColumnName = "goods_id", ColumnDescription = "商品Id")]
		public long GoodsId { get; set; } = 0;
		///<summary>
		/// 商品名称
		///</summary>
		[SugarColumn(ColumnName = "goods_name", ColumnDescription = "商品名称")]
		public string GoodsName { get; set; } = string.Empty;
		///<summary>
		/// 订单号
		///</summary>
		[SugarColumn(ColumnName = "order_id", ColumnDescription = "订单号")]
		public string OrderId { get; set; } = string.Empty;
		///<summary>
		/// 订单金额（单位：分）
		///</summary>
		[SugarColumn(ColumnName = "order_amount", ColumnDescription = "订单金额（单位：分）")]
		public int OrderAmount { get; set; } = 0;
		/// <summary>
		/// 订单类型
		/// </summary>
		[SugarColumn(ColumnName = "order_type", ColumnDescription = "订单类型")]
		public EnumOrderType OrderType { get; set; }
		/// <summary>
		/// 订单类型名称
		/// </summary>
		[SugarColumn(ColumnName = "order_type_name", ColumnDescription = "订单类型名称")]
		public string OrderTypeName { get; set; } = string.Empty;
		///<summary>
		/// 三方支付的订单号
		///</summary>
		[SugarColumn(ColumnName = "pay_order_no", ColumnDescription = "三方支付的订单号")]
		public string PayOrderNo { get; set; } = string.Empty;

		///<summary>
		/// 应付金额（单位：分）
		///</summary>
		[SugarColumn(ColumnName = "payable_amount", ColumnDescription = "应付金额（单位：分）")]
		public int PayableAmount { get; set; } = 0;

		///<summary>
		/// 实付金额（单位：分）
		///</summary>
		[SugarColumn(ColumnName = "actual_amount", ColumnDescription = "实付金额（单位：分）", IsNullable = true)]
		public int? ActualAmount { get; set; } = null;

		///<summary>
		/// 是否支付
		///</summary>
		[SugarColumn(ColumnName = "has_paid", ColumnDescription = "是否支付")]
		public bool HasPaid { get; set; } = false;
		/// <summary>
		/// 是否已经处理
		/// </summary>
		[SugarColumn(ColumnName = "has_deal", ColumnDescription = "是否已经处理")]
		public bool HasDeal { get; set; } = false;

		/// <summary>
		/// 订单处理时间
		/// </summary>
		[SugarColumn(ColumnName = "deal_time", ColumnDescription = "订单处理时间",IsNullable = true)]
		public DateTime? DealTime { get; set; }

		///<summary>
		/// 支付时间 
		///</summary>
		[SugarColumn(ColumnName = "pay_time", ColumnDescription = "支付时间", IsNullable = true)]
		public DateTime? PayTime { get; set; } = null;

		/// <summary>
		/// 支付类型
		/// </summary>
		[SugarColumn(ColumnName = "pay_type", ColumnDescription = "支付类型")]
		public EnumPayType PayType { get; set; }

		/// <summary>
		/// 支付类型名称
		/// </summary>
		[SugarColumn(ColumnName = "pay_type_name", ColumnDescription = "支付类型名称")]
		public string PayTypeName { get; set; } = string.Empty;

		/// <summary>
		/// 请求的IP地址
		/// </summary>
		[SugarColumn(ColumnName = "ip", ColumnDescription = "请求的IP地址")]
		public string Ip { get; set; } = string.Empty;

		/// <summary>
		/// 用户支付平台的OpenId
		/// </summary>
		[SugarColumn(ColumnName = "user_openid", ColumnDescription = "用户支付平台的OpenId")]
		public string OpenId { get; set; } = string.Empty;


		///<summary>
		/// 订单创建时间
		///</summary>
		[SugarColumn(ColumnName = "create_time", ColumnDescription = "订单创建时间")]
		public DateTime CreateTime { get; set; } = DateTime.Now;

		/// <summary>
		/// 扩展字段
		/// </summary>
		[SugarColumn(ColumnName = "ext1", ColumnDescription = "扩展字段",ColumnDataType = "text")]
		public string Ext1 { get; set; } = string.Empty;

		/// <summary>
		/// 扩展字段
		/// </summary>
		[SugarColumn(ColumnName = "ext2", ColumnDescription = "扩展字段", ColumnDataType = "text")]
		public string Ext2 { get; set; } = string.Empty;
        /// <summary>
        /// 扩展字段
        /// </summary>
        [SugarColumn(ColumnName = "ext3", ColumnDescription = "扩展字段", ColumnDataType = "text")]
		public string Ext3 { get; set; } = string.Empty;

        ///<summary>
        /// 删除状态
        ///</summary>
        [SugarColumn(ColumnName = "delete_status", ColumnDescription = "删除状态")]
		public bool DeleteStatus { get; set; } = false;

		/// <summary>
		/// 调试订单
		/// </summary>
		[SugarColumn(ColumnName = "is_debug", ColumnDescription = "调试订单")]
		public bool IsDebug { get; set; }

        /// <summary>
        /// 是否分账
        /// </summary>
        [SugarColumn(ColumnName = "is_profit_sharing", ColumnDescription = "是否分账")]
        public bool IsProfitSharing { get; set; }

        /// <summary>
        /// 是否已经分账
        /// </summary>
        [SugarColumn(ColumnName = "has_shared", ColumnDescription = "是否已经分账")]
        public bool HasShared { get; set; }

        /// <summary>
        /// 分账时间
        /// </summary>
        [SugarColumn(ColumnName = "shared_time", ColumnDescription = "分账时间", IsNullable = true)]
        public DateTime? SharedTime { get; set; }

		/// <summary>
		/// 订单明细
		/// </summary>
		[Navigate(NavigateType.OneToMany,nameof(OrderDetail.OrderId))]
        public List<OrderDetail>? Details { get; set; }
	}
}
